<!--
 * @Description: 房间数据
 *
 * @Author: XiongYaoYuan<xiongyaoyuan>
 * @Date: 2023-05-24 09:16:07
 * @FilePath: /yuxiuproweb/src/views/mes/pro/workorder/mods/add/room.vue
-->
<template>
  <el-dialog
    :close-on-click-modal="false"
    v-dialogDrag
    title="房间"
    :visible.sync="shows"
    width="700px"
    append-to-body
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="86px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="名称" prop="name">
            <el-select
              style="width: 100%"
              v-model="form.name"
              filterable
              allow-create
              default-first-option
              placeholder="请选择房间名称"
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="宽" prop="width">
            <el-input v-model="form.width" placeholder="请输入宽" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="高" prop="height">
            <el-input v-model="form.height" placeholder="请输入高" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" placeholder="请输入备注" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="图" prop="picture">
            <image-upload v-model="form.picture" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="shows = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  dicts: ["order_curtain_section"],
  props: {
    show: Boolean,
    type: {
      type: String,
      default: "add",
    },
    data: {
      type: Object,
    },
  },
  data() {
    return {
      // 表单参数
      form: {
        width: undefined,
        height: undefined,
        name: "",
        remark: "",
        picture: null,
      },
      // 表单校验
      rules: {
        name: [{ required: true, message: "请输入", trigger: "blur" }],
      },
      options: [
        {
          value: "主卧",
          label: "主卧",
        },
        {
          value: "Master bedroom",
          label: "Master bedroom",
        },
        {
          value: "客厅",
          label: "客厅",
        },
        {
          value: "Living room",
          label: "Living room",
        },
        {
          value: "次卧",
          label: "次卧",
        },
        {
          value: "Second bedroom",
          label: "Second bedroom",
        },
        {
          value: "书房",
          label: "书房",
        },
        {
          value: "Study room",
          label: "Study room",
        },
        {
          value: "男孩房",
          label: "男孩房",
        },
        {
          value: "Boy room",
          label: "Boy room",
        },
        {
          value: "女孩房",
          label: "女孩房",
        },
        {
          value: "Girl room",
          label: "Girl room",
        },
        {
          value: "Boy room",
          label: "Boy room",
        },
        {
          value: "阳台",
          label: "阳台",
        },
        {
          value: "Balcony",
          label: "Balcony",
        },
        {
          value: "餐厅",
          label: "餐厅",
        },
        {
          value: "Dining room",
          label: "Dining room",
        },
        {
          value: "客房",
          label: "客房",
        },
        {
          value: "Guest room",
          label: "Guest room",
        },
        {
          value: "飘窗",
          label: "飘窗",
        },
        {
          value: "Bay window",
          label: "Bay window",
        },
        {
          value: "长辈房",
          label: "长辈房",
        },
        {
          value: "Elderly Room",
          label: "Elderly Room",
        },
      ],
    };
  },
  computed: {
    shows: {
      get() {
        return this.show;
      },
      set(newValue) {
        this.$emit("update:show", newValue);
      },
    },
  },
  created() {
    if (this.data.room) {
      this.form = {
        ...this.data.room,
      };
    }
  },
  methods: {
    /** 提交按钮 */
    async submitForm() {
      try {
        await this.$refs["form"].validate();
        this.$emit("on-change", this.form);
        this.shows = false;
      } catch (e) {
        console.log(e);
      }
    },
  },
};
</script>
